#include "SceneObject.h"
#include "LightAbstractRenderer.h"
#include "Shape.h"

namespace LightPlayer{

	const char s_NoNameObject[] = "";

	SceneObject::SceneObject(){
		init();
	}

	void SceneObject::init(){
		m_Name = s_NoNameObject;
		m_pCharacter = NULL;
		m_Depth = 0;
		m_ClipDepth = 0;
		m_Transform = MATRIX();
		m_ColorTransfom = CXFORM();
		m_MorphRatio = 0;
		m_LockByActionScript = false;
	}

	void SceneObject::update( float dt ){

	}

	void SceneObject::draw( LightAbstractRenderer* pRenderer ){

		pRenderer->pushMatrix( m_Transform );
		pRenderer->pushCXFORM( m_ColorTransfom );

		m_pCharacter->draw(pRenderer,this);

		pRenderer->popCXFORM();
		pRenderer->popMatrix();
	}

	RECT SceneObject::getBounds() const{
		RECT bounds;
		if( getCharacter() && getCharacter()->getType() == eShapeCharacter ){
			const Shape* shape = dynamic_cast<const Shape*>( getCharacter() );
			if(shape){
				RECT shape_rect = shape->getBounds();
				shape_rect.transform( m_Transform );
				bounds.extend( shape_rect );
			}
		}
		return bounds;
	}

	CXFORM SceneObject::getResolvedCXFORM() const{
		return m_ColorTransfom;
	}

};